import {toast} from 'nc-lightapp-front';
import proFetch from '../../../../public/functions/project-fetch';

export default function addSearch() {
    const {endDate, orgVal, deptVal, psnVal} = this.state;
    if (!endDate) {
        toast({color: 'danger', content: this.state.json['cm6011-000011']}); /* 国际化处理： 请添加合同结束日期！*/
        return;
    }

    proFetch({
        url: '/nccloud/hrcm/contopinion/OpinionRemcAddQueryPsnAction.do',
        body: {
            pk_hrorg: this.props.orgVal.refpk,
            selorg: orgVal.refpk,
            seldepts: deptVal && deptVal.map(item => item.refpk).join(),
            selpkpsndocs: psnVal.map(item => item.refpk).join(),
            selenddate: endDate,
            valiselenddate: 'Y'
        }
    })
        .then((res) => {
            if (res.success) {
                if (res.data && res.data.contopinionadd) {
                    this.props.table.setAllTableData('contopinionadd', {rows: res.data.contopinionadd.rows});
                } else {
                    this.props.table.setAllTableData('contopinionadd', {rows: []});
                }
            }
        })
        .catch(error => {
            this.props.table.setAllTableData('contopinionadd', {rows: []});
        });
}
